package com.hkycu.goodsseckill;

import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.util.ArrayList;
import java.util.List;

class Solution1 {
    public static void main(String[] args){
        System.out.println(new Solution1().maxLengthBetweenEqualCharacters("mgntdygtxrvxjnwksqhxuxtrv"));
    }
    public int maxLengthBetweenEqualCharacters(String s) {


        char[] array= new char[s.length()];
        array = s.toCharArray();
        int count=0;
        boolean flag = true;
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0;i < array.length;i++){
            System.out.println(s.indexOf(array[1])+"===="+s.lastIndexOf(array[1]));
            if(s.lastIndexOf(array[i])!= s.indexOf(array[i])){
                count=s.lastIndexOf(array[i])-s.indexOf(array[i])-1;
                list.add(count);
                flag=false;
            }
        }

        if(flag){
            return -1;
        }
        int max=0;
        for (int m=0;m < list.size();m ++){
            max = list.get(0);
            if(list.get(m)>max){
                max = list.get(m);
            }
        }

        return max;
    }
}